home *** CD-ROM | disk | FTP | other *** search
- Path: datatamers.com!wnc
- From: wnc@datatamers.com ()
- Newsgroups: comp.lang.c
- Subject: newbie's problems w/ linux
- Date: 12 Feb 1996 17:02:00 GMT
- Organization: DATATAMERS
- Message-ID: <4fnrq8$53v@news.datatamers.com>
- NNTP-Posting-Host: dt1.datatamers.com
- X-Newsreader: TIN [version 1.2 PL2]
-
- i'm currently taking a beginners C class, and i was attempting to make a
- program which figures out GPA for my classes. I'm running windows 95, and
- when i compile it for DOS, it runs fine, but, when i compile it for
- linux, using gcc, i keep getting this same error, basically what happens
- is that after taking input through scanf(), it will skip the next
- scanf(), even though i'm using fflush(). here is a sample output of what
- happens.
-
-
- GPA version .9beta, written by wnc@datatamers.com
-
-
- How many classes do you have? 2
- What grade did you get in period 1? a
- What grade did you get in period 2? Do you have any AP classes?
-
- Your Total GPA for 2 period(s) is 0!
- Which is equivilent to a(n) F
-
-
- here is the source, if you can figure out what's wrong w/ it, please
- mail me at wnc@datatamers.com, thanks in advance.
-
- #include <stdio.h>
- void convert(void);
- void endo(void);
- float converted, gpa = 0., ap, donegpa;
- int periods;
- char grade, endofit[2], yesno;
- void main()
- {
- short int counter, counter2;
- printf("\n\n\n\n\n\n\nGPA version .9beta, written by wnc@datatamers.com\n\n\n");
- printf("How many classes do you have? ");
- scanf("%i", &periods);
- fflush(stdin);
- for ( counter = 1; counter <= periods; ++counter )
- {
- printf("What grade did you get in period %i? ", counter);
- scanf("%d", &grade);
- fflush(stdin);
- convert();
- gpa += converted;
- }
- printf("Do you have any AP classes? ");
- scanf("%d",& yesno);
- fflush(stdin);
- if (yesno=='y' || yesno=='Y')
- {
- printf("How many of them are AP? ");
- scanf("%f", &ap);
- gpa += ap;
- }
- donegpa= gpa / periods;
- endo();
- printf("\n\nYour Total GPA for %i period(s) is %.3g!\nWhich is equivilent to a(n) ", periods, donegpa);
- printf("%c%c\n\n\n", endofit[1], endofit[2]);
- }
- void convert(void)
- {
- switch (grade)
- {
- case 'a':
- case 'A':
- converted =4.;
- break;
- case 'b':
- case 'B':
- converted =3.;
- break;
- case 'c':
- case 'C':
- converted =2.;
- break;
- case 'd':
- case 'D':
- converted =1.;
- break;
- default:
- converted =0.;
- break;
- }
- }
- void endo(void)
- {
- if (donegpa>=4.0)
- {
- endofit[1] = 'A';
- endofit[2] = ' ';
- }
- else if (donegpa>=3.5)
- {
- endofit[1] = 'A';
- endofit[2] = '-';
- }
- else if (donegpa>3.0)
- {
- endofit[1] = 'B';
- endofit[2] = '+';
- }
- else if (donegpa==3.0)
- {
- endofit[1] = 'B';
- endofit[2] = ' ';
- }
- else if (donegpa>=2.5)
- {
- endofit[1] = 'B';
- endofit[2] = '-';
- }
- else if (donegpa>2.0)
- {
- endofit[1] = 'C';
- endofit[2] = '+';
- }
- else if (donegpa==2.0)
- {
- endofit[1] = 'C';
- endofit[2] = ' ';
- }
- else if (donegpa>=1.5)
- {
- endofit[1] = 'C';
- endofit[2] = '-';
- }
- else if (donegpa>1.0)
- {
- endofit[1] = 'D';
- endofit[2] = '+';
- }
- else if (donegpa==1.0)
- {
- endofit[1] = 'D';
- endofit[2] = ' ';
- }
- else if (donegpa>=.5)
- {
- endofit[1] = 'D';
- endofit[2] = '-';
- }
- else
- {
- endofit[1] = 'F';
- endofit[2] = ' ';
- }
- }
-
-
-